package com.busi.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.busi.util.Uploader;



/**
 * 图片上传使用的Servlet
 * ueditor版本:1.3.5
 * @author ankang
 * add on 2013-12-10
 */
public class ImageUpServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public static final String UEDITOR_IMAGES_DIR = "/uploadimage";
	public static final String[] ALLOW_IMAGE_TYPE = {"jpg","png","gif","jpeg"};

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");

		Uploader up = new Uploader(request);

		up.setSavePath(UEDITOR_IMAGES_DIR);
		String[] fileType = ALLOW_IMAGE_TYPE;
		up.setAllowFiles(fileType);
		up.setMaxSize(10000); //单位KB
		up.upload();
		response.getWriter().print("{'original':'"+up.getOriginalName()+"','url':'"+up.getUrl()+"','title':'"+up.getTitle()+"','state':'"+up.getState()+"'}");
	}

}
